//
//  ChangeAddressViewController.swift
//  AESOLAR_IOS
//
//  Created by Mr.Wang on 2019/9/27.
//  Copyright © 2019 Mr.Wang. All rights reserved.
//

import UIKit

class ChangeAddressViewController: SettingItemViewController {

    var editAddressBlock: (String) -> () = {_ in }
    
    let currentAddress: String
    
    init(currentAddress: String) {
        self.currentAddress = currentAddress
        super.init(nibName: nil, bundle: nil)
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    let address = TableViewItem.init(title: "地址".localized)
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        self.navigationItem.title = "定位地址".localized
        self.navigationItem.rightBarButtonItem = UIBarButtonItem.init(title: "保存".localized, style: .plain, target: self, action: #selector(save))
        
        tableView.setHeaderHeight(0.1)
        tableView.backgroundColor = #colorLiteral(red: 0.9724436402, green: 0.972609818, blue: 0.9724331498, alpha: 1)
        
        address.accessoryType = .none
        address.textFieldValue = self.currentAddress
        address.textFieldSetUp = { textField in
            textField.placeholder = "请输入地址".localized
        }
    }
    
    @objc func save() {
        self.navigationController?.popViewController(animated: true)
        editAddressBlock(address.textFieldValue)
    }
    
    override func sectionArray() -> [TableViewSection] {
        return [TableViewSection.section(items: [address])]
    }
    
    override func navigationBarStyle() -> NavigationBarStyle {
        return .baseColor
    }
    
}
